<template>
  <div class="home">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="auto">
        <div class="logo"></div>
        <el-menu
          default-active="1"
          background-color="#F9F9F9"
          class="el-menu-admin"
          router
          :unique-opened='uniqueFlag'
          text-color="#000000"
          active-text-color="#409EFF"
          @open="handleOpen"
          :collapse="isCollapse"
          @close="handleClose">
          <el-submenu :index="itme.path" v-for="itme in dataList" :key="itme.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{itme.authName}}</span>
            </template>
              <el-menu-item :index="value.path" v-for="value in itme.children" :key="value.id">
                <i class="el-icon-menu"></i>
                <span>{{value.authName}}</span>
              </el-menu-item>
          </el-submenu>
      </el-menu>
      </el-aside>
      <el-container>
        <!-- 头部部分 -->
        <el-header>
          <div class="myicon myicon-menu toggle-btn" @click="myisCollapse"></div>
          <div class="system-title">传值播客后台管理系统</div>
          <div class="welcome">
            <span>您好，{{username}}</span>
            <el-button type="warning" round @click="secede">退出</el-button>
          </div>
        </el-header>
        <!-- 内容区域 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {Homemenu} from '@/api'
export default {
  data () {
    return {
      isCollapse: false,
      uniqueFlag: true,
      username: '?????',
      dataList: []
    }
  },
  mounted () {
    this.username = localStorage.getItem('username')
    this.menuData()
  },
  methods: {
    handleOpen (key, keyPath) {
      // console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      // console.log(key, keyPath)
    },
    // 这是切换收起与展开
    myisCollapse () {
      this.isCollapse = !this.isCollapse
    },
    // 退出登录
    secede () {
      localStorage.removeItem('mytoken')
      this.$router.push({name: 'login'})
    },
    // 获取左侧菜单列表
    menuData () {
      Homemenu()
        .then(res => {
          // console.log(res)
          this.dataList = res.data
        })
    }
  }
}
</script>

<style lang="scss" scoped>
  .home {
    height: 100%;
    .el-menu-admin:not(.el-menu--collapse) {
      width: 200px;
      min-height: 400px;
    }
    .el-container {
      height: 100%;
    }
    .el-aside {
      background-color: #F9F9F9;
    }
    .el-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #409EFF;
    }
    .logo {
      height:60px;
      background: url(../assets/logo.png);
      background-size: cover;
      background-color: white;
    }
    .toggle-btn {
      padding: 0 15px;
      margin-left: -20px;
      font-size: 36px;
      color: white;
      cursor: pointer;
      line-height: 60px;
      &:hover {
        background-color: #4292CF;
      }
    }
    .system-title {
      font-size: 28px;
      color: white;
    }
    .welcome, {
      color: white;
    }
  }
</style>
